from copy import deepcopy
from research.calcor.calcor_logic import logic_calc
class countN:
    def __init__(self,args,timeperiod):#feild
        self.timekey=None
        self.predata=[]
        self.args=args
        self.timeperiod=timeperiod
    def oncalc(self,b,timekey=None):
        r0 = 0
        r = logic_calc(self.args, b)
        if r==True:
            r0 = 1
        if timekey:
            if self.timekey == self.timekey:
                self.predata[-1] = r0
            self.timekey = timekey
        else:
            self.predata.append(r0)
        if len(self.predata) > self.timeperiod:
            self.predata.pop(0)
        rst=sum(self.predata)
        return rst

if __name__=="__main__":
    pass